package random;

import java.util.HashMap;

public class Class3 {

    public int lengthOfLongestSubstring(String s) {
      int max=Integer.MIN_VALUE;
      int left=0;
      int right=0;
      HashMap<Character, Integer> window = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            //TODO:2024/1/4 相当于记录遍历过得元素的个数
            right++;
            window.put(c,window.getOrDefault(c,0)+1);
            while (window.get(c)>1){
                char c1 = s.charAt(left);
                left++;
                window.put(c1,window.get(c1)-1);
            }
            max=Math.max(max,right-left);
        }
        return  max;
    }

    public static void main(String[] args) {

        String  a="adcae";
        Class3 class3 = new Class3();
        int i = class3.lengthOfLongestSubstring(a);
        System.out.println(i);


    }



}
